package org.jackysoft.struts2.admin;

import java.util.Collection;

import javax.annotation.Resource;

import org.apache.struts2.convention.annotation.Namespace;
import org.jackysoft.entity.Attachment;
import org.jackysoft.entity.HibernateWorkflowEntry;
import org.jackysoft.service.AttachmentService;
import org.jackysoft.struts2.workflow.AbstractWorkflowAction;
import org.springframework.beans.factory.config.BeanDefinition;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;



@Controller
@Namespace("/admin/attachment")
@Scope(BeanDefinition.SCOPE_PROTOTYPE)
public class AttachmentAction extends AbstractWorkflowAction<Attachment>{

	private static final long serialVersionUID = -5576568733572374417L;
	private AttachmentService service;
	private Attachment bean;
	private Collection<Attachment> beans;

	
	public String append() throws Exception {
	    service.create(upLoads,upLoadsFileName,workflowId);
		return SUCCESS;
	}
	
	
	public String upload() throws Exception{
		bean = service.upload(upLoad, upLoadFileName);
		return SUCCESS;
	}
	

	public String uploads() throws Exception{
		beans = service.upload(upLoads, upLoadsFileName);
		return SUCCESS;
	}
	
	
	@Override
	public String start() throws Exception {
		HibernateWorkflowEntry hw = (HibernateWorkflowEntry) workflowService.findEntry(workflowId);
		beans = hw.getAttachment();
		return "start";
	}

	
	public String removeappend()throws Exception{
		service.remove(bean,workflowId);
		return SUCCESS;
	}
	
	public AttachmentService getService() {
		return service;
	}

	@Resource
	public void setService(AttachmentService attachmentService) {
		this.service = attachmentService;
	}

		

	public Attachment getBean() {
		return bean;
	}

	public void setBean(Attachment bean) {
		this.bean = bean;
	}

	public Collection<Attachment> getBeans() {
		return beans;
	}

	public void setBeans(Collection<Attachment> beans) {
		this.beans = beans;
	}	
	
}
